﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace canyinguanlixitong
{
    public partial class ydgl预定管理 : Form
    {
        public ydgl预定管理()
        {
            InitializeComponent();
        }

        private void ydgl预定管理_Load(object sender, EventArgs e)
        {
            chaxun();
            chaxun2();
            chaxun3();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            bkyy宾客预约 frm = new bkyy宾客预约();
            frm.Show();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            plyd批量预定 frm = new plyd批量预定();
            frm.Show();
        }

        private void button4_Click(object sender, EventArgs e)
        {
            bianji编辑 frm = new bianji编辑();
            frm.stu = dataGridView1.SelectedCells[0].Value.ToString();
            frm.Show();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            chaxun();
        }
        string str = "Data Source=.;Initial Catalog=Supermarket management system;Integrated Security=True";
        public void chaxun()
        {
            SqlConnection con = new SqlConnection(str);
            con.Open();
            try
            {
                string akn = @"select ydID,yhhm,ydTime,ydCz,czmc,czzt,ydMoney,ydQi,czy from [Scheduled management]  
where ydID like '%" + this.txtname.Text + "%'";
                SqlCommand com = new SqlCommand(akn, con);
                SqlDataAdapter an = new SqlDataAdapter(akn, con);
                DataSet hj = new DataSet("cj");
                if (hj.Tables["cj"] != null)
                {
                    hj.Tables["cj"].Clear();
                }
                an.Fill(hj, "cj");
                dataGridView1.DataSource = hj.Tables["cj"];
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        DataSet gg = new DataSet("ov");
        public void chaxun2()
        {
            try
            {
                SqlConnection con = new SqlConnection(str);
                con.Open();
                string akn = @"select ydID,yhhm,ydTime,czmc,czzt,ydMoney,ydQi,czy from [Scheduled management]";
                SqlDataAdapter an = new SqlDataAdapter(akn, con);
                an.Fill(gg, "ov");
                this.dataGridView2.DataSource = gg.Tables["ov"];
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        DataSet ac = new DataSet("cd");
        public void chaxun3()
        {
            try
            {
                SqlConnection con = new SqlConnection(str);
                string akn = @"select czmc,ydCz,czzt,ydMoney from [Scheduled management]";
                SqlDataAdapter an = new SqlDataAdapter(akn, con);
                if (ac.Tables["cd"] != null)
                {
                    ac.Tables["cd"].Clear();
                }
                an.Fill(ac, "cd");
                this.dataGridView3.DataSource = ac.Tables["cd"];
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void 添加预定ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            bkyy宾客预约 frm = new bkyy宾客预约();
            frm.Show();
        }

        private void 编辑预定ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            bianji编辑 frm = new bianji编辑();
            frm.stu = dataGridView1.SelectedCells[0].Value.ToString();
            frm.Show();
        }

        private void 取消预定ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            SqlConnection con = new SqlConnection(str);
            con.Open();
            try
            {
                string stu = dataGridView1.SelectedCells[0].Value.ToString();
                string ace = @"delete from [Scheduled management] where ydID='" + stu + "'";
                SqlCommand com = new SqlCommand(ace, con);
                int avg = com.ExecuteNonQuery();
                if (avg > 0)
                {
                    MessageBox.Show("删除成功", "提示");
                }
                else
                {
                    MessageBox.Show("删除失败", "提示");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                con.Close();
            }
            MessageBox.Show("删除完成", "提示");
        }

        private void button5_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void button2_Click_1(object sender, EventArgs e)
        {
            bkyy宾客预约 frm = new bkyy宾客预约();
            frm.Show();
        }

        private void button3_Click_1(object sender, EventArgs e)
        {
            plyd批量预定 frm = new plyd批量预定();
            frm.Show();
        }

        private void button4_Click_1(object sender, EventArgs e)
        {
            bianji编辑 frm = new bianji编辑();
            frm.stu = dataGridView1.SelectedCells[0].Value.ToString();
            frm.Show();
        }

        private void button1_Click_1(object sender, EventArgs e)
        {
            chaxun();
        }

        private void 删除预订ToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }

        private void 添加预订ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            bkyy宾客预约 frm = new bkyy宾客预约();
            frm.Show();
        }

        private void 修改预订ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            bianji编辑 frm = new bianji编辑();
            frm.stu = dataGridView1.SelectedCells[0].Value.ToString();
            frm.Show();
        }

        private void 删除预订ToolStripMenuItem_Click_1(object sender, EventArgs e)
        {
            SqlConnection con = new SqlConnection(str);
            con.Open();
            try
            {
                string stu = dataGridView1.SelectedCells[0].Value.ToString();
                string ace = @"delete from [Scheduled management] where ydID='" + stu + "'";
                SqlCommand com = new SqlCommand(ace, con);
                int avg = com.ExecuteNonQuery();
                if (avg > 0)
                {
                    MessageBox.Show("删除成功", "提示");
                }
                else
                {
                    MessageBox.Show("删除失败", "提示");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                con.Close();
            }
            MessageBox.Show("删除完成", "提示");
        }

        private void button5_Click_1(object sender, EventArgs e)
        {
                        SqlConnection con = new SqlConnection(str);
            con.Open();
            try
            {
                string stu = dataGridView1.SelectedCells[0].Value.ToString();
                string ace = @"delete from [Scheduled management] where ydID='" + stu + "'";
                SqlCommand com = new SqlCommand(ace, con);
                int avg = com.ExecuteNonQuery();
                if (avg > 0)
                {
                    MessageBox.Show("删除成功", "提示");
                }
                else
                {
                    MessageBox.Show("删除失败", "提示");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                con.Close();
            }
            MessageBox.Show("删除完成", "提示");
        }

        private void button3_Click_2(object sender, EventArgs e)
        {
        this.Close();
        }
        }
    }
